<template>
	<view class="mainbgc" @click="hidefalse">
		<!-- 选择欠款 -->
		<u-popup :show="qkuanshow" :round="10" mode="center">
			<view class="zhengds ">
				<view class="strongtext" style="text-align: center;">请输入欠款金额</view>
				<input type="text" class="shurudh margin_top" placeholder="请输入欠款金额">
				<view class="flexcenter margin_top">
					<view class="btns btn1" @click="qkuanclose">取消</view>
					<view class="btns btn2">确定</view>
				</view>
			</view>
		</u-popup>
		<!-- 优惠 -->
		<u-popup :show="yhshow" :round="10" mode="center">
			<view class="zhengds ">
				<view class="strongtext" style="text-align: center;">请输入优惠金额</view>
				<input type="text" class="shurudh margin_top" placeholder="请输入优惠金额" v-model="money">
				<view class="flexcenter margin_top">
					<view class="btns btn1" @click="yhclose">取消</view>
					<view class="btns btn2" @click="suremoney">确定</view>
				</view>
			</view>
		</u-popup>
		<!-- 加载进价 -->
		<u-popup :show="jzshow" :round="10" mode="center">
			<view class="zhengds ">
				<view class="nostrongtext" style="line-height: 40rpx;">
					点击“加载进价”后，会将无法采购价格的商品按照上次进价/预设进价进行加载，是否继续？
				</view>
				<view class="flexcenter margin_top">
					<view class="btns btn1" @click="jzclose">取消</view>
					<view class="btns btn2">确定</view>
				</view>
			</view>
		</u-popup>
		<!-- 整单备注 -->
		<u-popup :show="xsshow" :round="10" mode="center">
			<view class="zhengds ">
				<view class="strongtext" style="text-align: center;">请输入整单备注</view>
				<input type="text" class="shurudh margin_top" placeholder="请输入整单备注" v-model="note_text">
				<view class="flexcenter margin_top">
					<view class="btns btn1" @click="xsclose">取消</view>
					<view class="btns btn2" @click="surenote">确定</view>
				</view>
			</view>
		</u-popup>
		<!-- 清空单据 -->
		<u-popup :show="qkshow" :round="10" mode="center">
			<view class="zhengds">
				<view class="strongtext margin_top" style="text-align: center;">确认清空单据</view>
				<view class="flexcenter margin_top">
					<view class="btns btn1" @click="qkclose">取消</view>
					<view class="btns btn2">确定</view>
				</view>
			</view>
		</u-popup>
		<header-top :messageInfo="{typeFlag:true,message:'订货单',liner:false}">
			<view class="rightmsg" slot="rightmsg">
				<view class="rightmsg_content flexleft">
					<view class="nostrongtext margin_right" @click="submit" v-if="purchase_code==''">提交</view>
					<view class="diandiandian" @click.stop="dian">
						<view class="selectcontent" v-show="selectshow">
							<view class="topbox">
								<view class="flexleft itemselect" @click.stop="zhifufangshi">
									<view class="leftimage margin_right">
										<image src="../../../static/image/system/zhifu.png" mode=""></image>
									</view>
									<view>支付方式</view>
								</view>
							</view>
							<view class="topbox">
								<view class="flexleft itemselect" @click.stop="youhui">
									<view class="leftimage margin_right">
										<image src="../../../static/image/system/youhui.png" mode=""></image>
									</view>
									<view>优惠</view>
								</view>
							</view>
							<view class="topbox">
								<view class="flexleft itemselect" @click.stop="xiaosbz">
									<view class="leftimage margin_right">
										<image src="../../../static/image/system/beizhu.png" mode=""></image>
									</view>
									<view>整单备注</view>
								</view>
							</view>
							<view class="topbox">
								<view class="flexleft itemselect" @click.stop="qingkong">
									<view class="leftimage margin_right">
										<image src="../../../static/image/system/shanchu.png" mode=""></image>
									</view>
									<view>清空单据</view>
								</view>
							</view>
							<view class="topbox">
								<view class="flexleft itemselect" @click.stop="receiptTest">
									<view class="leftimage margin_right">
										<image src="../../../static/image/system/dayin.png" mode=""></image>
									</view>
									<view>打印</view>
								</view>
							</view>
							<view class="sanjiao"></view>
						</view>
					</view>
				</view>
			</view>
		</header-top>
		<!-- 选择供应商选择仓库 -->
		<view class="margin_top ffffff mainpadding ">
			<view class="flexleft">
				<view :class="kehu.name?'lansebtn allbtn':'allbtn huisebtn'" @click="selectkh">
					{{kehu.name || '选择客户'}}
				</view>
			</view>
			<view class="flexbetween margin_top">
				<view class="strongtext ">客户：{{kehu.name}}</view>
				<view class="nostrongtext">{{dataAll.purchase_time}}</view>
			</view>
			<view class="flexbetween margin_top">
				<view class="nostrongtext ">{{dataAll.purchase_code}}</view>
				<!-- <view class="nostrongtext">现结</view> -->
			</view>
			<view class="huisetext margin_top">整单备注：{{dataAll.note || ''}}</view>
		</view>
		<!--商品名称-->
		<template v-if="dataAll.goods_info.length != 0">
			<view class="ffffff margin_top">
				<view class="flexbetween mainpadding">
					<view class="bigtext flex2">商品名称</view>
					<view class="bigtext flex1s">数量</view>
					<view class="bigtext flex1">单价</view>
				</view>
				<view class=" mainpadding2" v-for="item in dataAll.goods_info" :key="item.id" @click="xgdjmx(item)">
					<view class="shangpin">
						<view class="flexbetween">
							<view class="shangtext flex2">{{item.goods_name}}</view>
							<view class="shangtext flex1s">*{{item.number}}</view>
							<view class="shangtext flex1" v-if="item.purchase_type!=3">{{item.unit_price}}</view>
							<view class="hongsetext strongtext flex1" v-if="item.purchase_type==3">赠品</view>
						</view>
						<view class="flexbetween margin_top">
							<view class="huisetext">备注：{{item.remark}}</view>
							<view class="lansetext" v-if="item.purchase_type!=3">￥{{item.all_money}}</view>
						</view>
					</view>
				</view>
			</view>
			<!-- 计数量 -->
			<view class="mainpadding2" style="padding-bottom: 200rpx;">
				<view class="flexleft margin_top">
					<view class="nostrongtext xiaoshou youbianju">优惠:
						<text class="lvsetext">{{dataAll.preferential_money}}元</text>
					</view>
					<view class="nostrongtext xiaoshou youbianju">欠款:
						<text class="hongsetext">{{dataAll.arrears}}元</text>
					</view>
				</view>
				<view class="flexleft margin_top">
					<view class="nostrongtext youbianju">合计:
						<text class="lvsetext">{{dataAll.all_money}}元</text>
					</view>
					<view class="nostrongtext xiaoshou youbianju" v-for="item in dataAll.pay_data" :key="item.accounts_id">
						{{item.account_name}}:
						<text class="lvsetext">{{item.money}}元</text>
					</view>
				</view>
			</view>
		</template>
		<!-- 底部 -->
		<view class="ffffff dibu flexbetween">
			<view class="shuruk flexbetween">
				<input type="text" class="inputs" placeholder="输入商品首拼/编号" disabled disabled="" @click="tianjia(1)">
				<view class="tianjia" @click="tianjia(2)">添加</view>
			</view>
			<view class="scan2" ></view>
		</view>
		<!-- 客户档案 -->
		<selectCustomer :message="{kehuShow:kehuShow}" @kehuSure="kehuSure"></selectCustomer>
		<u-popup :show="bfchange" :round="10" mode="center">
			<view class="flexcenter margin_top">提示</view>
			<view class="zhengds ">
				<view class="strongtext" style="text-align: center;">修改客户后可能导致某些数据流失</view>
				<view class="strongtext" style="text-align: center;">是否确认修改</view>
				<view class="flexcenter margin_top">
					<view class="btns btn1" @click="bfsure(1)">取消</view>
					<view class="btns btn2" @click="bfsure(2)">确定</view>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	const tsc = require("@/util/ble/tsc.js");
	const esc = require("@/util/ble/esc.js");
	const encode = require("@/util/ble/encoding.js");
	import {
		mapState
	} from 'vuex';
	export default {
		data() {
			return {
				// 下拉菜单
				selectshow: false,
				zdshow: false,
				xsshow: false,
				qkshow: false,
				qkuanshow: false,
				yhshow: false,
				jzshow: false,
				// 客户档案
				kehuShow: false,
				kehu: {
					id: "",
					name: ""
				},
				purchase_code: "",
				preferential_money: "", //优惠金额实际内容
				money: "", //优惠金额
				note: "", //整单备注实际内容
				note_text: "", //整单备注
				dataAll: {
					id: 4, //ID
					purchase_code: "DHD20221110001", //单据编号
					purchase_time: "2022-11-15", //单据日期
					customers_id: 1, //客户ID
					goods_kind: 5, //商品种类
					number: 18, //销货数量
					all_money: 210, //销货金额
					preferential_money: 15, //优惠金额
					real_money: 180, //优惠后金额
					pay_status: "2", //收款状态:0=未收款,1=全部收款,2=部分收款
					examine_status: "-1", //审核状态:0=未审核,1=已审核,-1草稿
					examine_time: 0, //审核时间
					pay_money: 150, //已付款金额

					pay_data: [{
						accounts_id: "1",
						money: "100", //金额
						account_name: "现金" //账户
					}], //付款方式
					note: "单据备注", //备注
					arrears: 30, //本次欠款
					arrear_account: -48, //总欠款
					receive_account: "0.0", //预收款
					customer_name: "kehu1", //客户
					settlementtype_name: "现金", //客户结算方式
					goods_info: [{
						id: 17, //ID
						purchase_type: "1", //类型:1=销货,2=退货,3=赠品
						goods_code: "SP001", //商品编号
						goods_unit: 4, //单位ID
						number: 10, //数量
						unit_price: 3, //销货单价
						all_money: 30, //购货金额
						remark: "销货商品备注", //备注
						manufacture: null, //生产日期
						goods_name: "这是一件饮料ma?", //名称
						unit_name: "瓶", //计量单位
						unit_str: "1提/12瓶", //单位换算
						manufacture_text: "1970-01-01" //生产日期
					}, ],
				},
				bf_data:{
					visit_id:"",//拜访id
					customers_id:"",//客户id
				},
				bf_model:false,//拜访模式，只有在拜访客户进来的时候才会开启
				bfchange:false,//是否改变客户弹出层,
				// 打印机技术参数
				sendContent: "../../../static/image/news/boy.png",
				looptime: 0,
				currentTime: 1,
				lastData: 0,
				oneTimeData: 0,
				returnResult: "",
				canvasWidth: 180,
				canvasHeight: 180,
				imageSrc: '../../static/img/abc_ic_star_black_16dp.png',
				buffSize: [],
				buffIndex: 0,
				printNum: [],
				printNumIndex: 0,
				printerNum: 1,
				currentPrint: 1,
				isReceiptSend: false,
				isLabelSend: false,
				// 打印机技术结束
			}
		},
		onLoad(options) {
			uni.hideTabBar(); //隐藏tab
			if(options.purchase_code){
				this.purchase_code = options.purchase_code
			}else if(options.msg){
				let data = JSON.parse(decodeURIComponent(options.msg));
				this.bf_data = data
				this.bf_model = true
				console.log(data,"拜访跳转接收参数")
				this.bfinit()
			}
			// 打印机
			let that = this;
			let {
				BLEInformation
			} = that.Bluetooth;
			// 打印机结束
		},
		// 打印机开始
		computed: mapState(['sysinfo', 'Bluetooth']),
		onReady() {
			let list = []
			let numList = []
			let j = 0
			for (let i = 20; i < 200; i += 10) {
				list[j] = i;
				j++
			}
			for (let i = 1; i < 10; i++) {
				numList[i - 1] = i
			}
			this.buffSize = list;
			this.oneTimeData = list[0];
			this.printNum = numList;
			this.printerNum = numList[0];
		},
		onUnload() {
			let that = this;
			let {
				BLEInformation
			} = that.Bluetooth;
		},
		// 打印机结束
		onShow() {
			this.selectshow = false
			this.init();
			uni.$off('getkhitem');//解绑当前事件，否则重复调用
			uni.$on('getkhitem', (data) => {
				// console.log(data,"返回数据")
				this.kehu.name = data.customer_name
				this.kehu.id = data.id
				this.refreshmsg()
			})
			// 打印机开始
			let that = this;
			let width;
			let height;
			uni.getImageInfo({
				src: that.imageSrc,
				success(res) {
					console.log(res.width)
					console.log(res.height)
					width = res.width
					height = res.height
					that.canvasWidth = res.width;
					that.canvasHeight = res.height;
				}
			})
			const ctx = uni.createCanvasContext("edit_area_canvas", this);
			// if (app.globalData.platform == "android") {
			//   ctx.translate(width, height)
			//   ctx.rotate(180 * Math.PI / 180)
			// }
			ctx.drawImage(this.imageSrc, 0, 0, width, height);
			ctx.draw();
			// 打印机结束
		},
		methods: {
			selectkh(){
				if(this.purchase_code!=''){
					httpRequest.toast('当前单据已提交，无法进行此类操作')
					return
				}
				uni.navigateTo({
					url:"/pages/workbench/xiaoshou/kehulist"
				})
			},
			bfinit(){
				let _this = this;
				httpRequest.request('appapi/manage/goods/order_detail', 'POST', {
					purchase_code:this.purchase_code,
					visit_customer_id:this.bf_data.visit_id,
				}, false, false, true).then(res => {
					if(this.bf_model){//拜访模式开启
						if(res.data.customers_id!=this.bf_data.customers_id && res.data.customers_id!=''){
							this.bfchange = true
						}
					}
				}).catch(err => {
					// httpRequest.toast(err.msg);
				})
			},
			bfsure(value){
				this.bfchange = false
				if(value==2){
					this.kehu.id = this.bf_data.customers_id
					this.bf_model = false
					this.refreshmsg()
				}
			},
			init() {
				let _this = this;
				httpRequest.request('appapi/manage/goods/order_detail', 'POST', {
					purchase_code: this.purchase_code,
					visit_customer_id:this.bf_data.visit_id,
				}, false, false, true).then(res => {
					this.dataAll = res.data
					this.kehu.name = res.data.customer_name //客户名称
					this.kehu.id = res.data.customers_id == 0 ? '' : res.data.customers_id //客户id
					this.note = res.data.note //整单备注
					this.note_text = res.data.note //整单备注
					this.preferential_money = res.data.preferential_money //优惠金额
					this.money = res.data.preferential_money //优惠金额
					// stores_id
					console.log(this.dataAll, 888)
				}).catch(err => {
					// httpRequest.toast(err.msg);
				})
			},
			// 数据刷新
			refreshmsg() {
				let _this = this
				httpRequest.request('appapi/manage/goods/order_add', 'POST', {
					purchase_code: this.dataAll.purchase_code,
					customers_id: this.kehu.id, //客户id
					preferential_money: this.preferential_money, //优惠金额
					note: this.note //整单备注
				}, false, false, true).then(res => {
					if (res.code == 1) {
						this.init()
					} else {
						httpRequest.toast(res.msg);
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			//跳转修改单据明细
			xgdjmx(item) {
				if (this.purchase_code != '') {
					// httpRequest.toast('当前单据已提交，无法进行此类操作')
					return
				}
				let obj = {
					type: 4, //1销售单，2退货单，3采购单，4订货单
					sales_info_id: item.id,
					store_id: '',
					price: ''
				}
				uni.navigateTo({
					url: '/pages/workbench/xiaoshou/xiugaidjmx?msg=' + encodeURIComponent(JSON.stringify(obj))
				})
			},
			//跳转添加商品页面
			tianjia(value) {
				if (this.purchase_code != '' || this.purchase_code == undefined) {
					httpRequest.toast('当前单据已提交，无法进行此类操作')
					return
				}
				if(this.kehu.id==""){
					httpRequest.toast("请选择客户")
					return false
				}
				let data = {
					type: 4, //1销货单，2退货单，3采购单,4订货单
					ck_id: "", //仓库id
					sp_code: this.dataAll.purchase_code, //订单编号
					mr_sjstate: "", //支付方式
					kh_id: this.kehu.id, //此处本应传客户id但此页面并没有选择客户的功能，传递供应商编号
					yg_id: "",
					goods_ids: []
				}
				uni.navigateTo({
					url: '/pages/workbench/xiaoshou/tianjspxsdd?getmsg=' + encodeURIComponent(JSON.stringify(
						data))
				})
			},
			// 客户档案确定
			kehuSure(e) {
				this.kehuShow = false
				// console.log(this.purchase_code,"this.purchase_code")
				if (this.purchase_code != '') {
					httpRequest.toast('当前单据已提交，无法进行此类操作')
					return
				}
				if (e) {
					this.kehu.id = e.value[0].id
					this.kehu.name = e.value[0].name
				}
				this.refreshmsg()
			},
			// 订货单明细
			onclick() {
				uni.navigateTo({
					url: '/pages/workbench/caigou/dinghuodetail'
				})
			},
			// 跳转支付方式
			zhifufangshi() {
				if (this.purchase_code != '') {
					httpRequest.toast('当前单据已提交，无法进行此类操作')
					return
				}
				// if(this.dataAll.real_money==0){
				// 	httpRequest.toast("请先选择付费的商品")
				// 	return
				// }
				let obj = {
					type: 4, //1销货单，2退货单，3采购单,4订货单
					purchase_code: this.dataAll.purchase_code,
					heji: this.dataAll.all_money, //合计
					yushoukuan: this.dataAll.receive_account, //预收款
					customers_id:this.dataAll.customers_id
				}
				console.log(obj)
				uni.navigateTo({
					url: '/pages/workbench/caigou/shuruzhifje?msg=' + encodeURIComponent(JSON.stringify(obj))
				})
			},
			// 提交单据
			submit() {
				if(this.kehu.id==""){
					httpRequest.toast("请选择客户")
					return false
				}
				let _this = this
				httpRequest.request('appapi/manage/goods/order_submit', 'POST', {
					purchase_code: this.dataAll.purchase_code,
					visit_customer_id:this.bf_data.visit_id
				}, false, false, true).then(res => {
					httpRequest.toast(res.msg)
					if(res.code==1){
						setTimeout(function() {
							uni.navigateBack(1)
						}, 1000)
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			dian() {
				if(this.kehu.id==""){
					httpRequest.toast("请选择客户")
					return false
				}
				this.selectshow = this.selectshow == false ? true : false
			},
			hidefalse() {
				if (this.selectshow == true) {
					this.selectshow = false
					return
				}
			},
			//整单备注
			zdopen() {
				// console.log('open');
			},
			zdclose() {
				this.zdshow = false
				// console.log('close');
			},
			//销售备注
			xsclose() {
				this.xsshow = false
				// console.log('close');
			},
			// 整单备注确认
			surenote() {
				this.xsshow = false
				this.note = this.note_text
				this.refreshmsg()
			},
			xiaosbz() {
				this.selectshow = false
				this.xsshow = true
			},
			//清空数据
			qkclose() {
				this.qkshow = false
				// console.log('close');
			},
			qingkong() {
				this.selectshow = false
				this.qkshow = true
			},
			//欠款
			qkuanclose() {
				this.qkuanshow = false
				// console.log('close');
			},
			qiankuan() {
				this.selectshow = false
				this.qkuanshow = true
			},
			//优惠
			yhclose() {
				this.yhshow = false
			},
			// 优惠确认
			suremoney() {
				this.yhshow = false
				this.preferential_money = this.money
				this.refreshmsg()
			},
			youhui() {
				this.selectshow = false
				this.yhshow = true
			},
			//加载
			jzclose() {
				this.jzshow = false
			},
			jiazaijj() {
				this.selectshow = false
				this.jzshow = true
			},
			// 打印机开始
			receiptTest() {
				this.selectshow = false
				var that = this;
				var canvasWidth = that.canvasWidth
				var canvasHeight = that.canvasHeight
				var command = esc.jpPrinter.createNew()
				command.init()
				// 标题
				command.bold(1); //加粗
				command.setFontSize(16); //字体大小
				command.setSelectJustification(1) //居中0左对齐1居中对齐2右对齐
				command.rowSpace(100);
				command.setText("订货单");
				command.setPrint();
				command.rowSpace(60); //行间距
				command.bold(0); //取消加粗
				command.setFontSize(0); //正常字体
				// 内容
				command.bold(1); //加粗
				command.setSelectJustification(0) //居中0左对齐1居中对齐2右对齐
				command.setText("客户名称：" + that.kehu.name);
				command.setPrint();
				command.setText("时间：" + that.dataAll.purchase_time);
				command.setPrint();
				command.bold(0); //加粗
				command.setAbsolutePrintPosition(0);
				command.setText("单据编号：" + that.dataAll.purchase_code);
				command.setPrint()
				let note = that.dataAll.note?that.dataAll.note:""
				command.setText("备注：" + note);
				command.setPrint();
				// 表格
				command.rowSpace(80); //间距
				command.bold(5); //加粗
				command.setText("商品名称");
				command.setAbsolutePrintPosition(270);
				command.setText("数量");
				command.setAbsolutePrintPosition(380);
				command.setText("单价");
				command.setPrint()
				command.bold(0); //加粗
				that.dataAll.goods_info.forEach(item=>{
					command.setText(item.goods_name);
					command.setAbsolutePrintPosition(270);
					command.setText("*"+item.number);
					command.setAbsolutePrintPosition(380);
					if(item.purchase_type!=3){
						command.setText(item.unit_price);
					}else{
						command.setText("赠品");
					}
					command.setPrint()
					command.setText("备注："+item.remark);
					command.setAbsolutePrintPosition(380);
					if(item.purchase_type!=3){
						command.setText("￥"+item.all_money);
					}
					command.setPrint()
				})
				command.bold(5); //加粗
				command.setText("合计："+that.dataAll.all_money);
				command.setLeftMargin(200)
				command.setText("优惠："+that.dataAll.preferential_money);
				command.setLeftMargin(200)
				command.setText("欠款："+that.dataAll.arrears);
				command.setLeftMargin(200)
				command.setPrint()
				that.dataAll.pay_data.forEach(item=>{
					command.setText(item.account_name+"："+item.money);
					command.setLeftMargin(200)
				})
				//时间
				// 	command.setSelectJustification(0);//居左
				// 	command.setText("时间：2019-11-11 12:10:30");
				// 	command.setPrint();
				// 	//编号
				// 	command.setSelectJustification(0);//居左
				// 	command.setText("编号：SD10000000000000000");
				// 	command.setPrintAndFeed(80);//打印并走纸feed个单位
				// 	//列表
				// 	command.rowSpace(80);//间距
				// 	command.bold(5);//加粗
				// 	command.setText("货号");
				// 	command.setAbsolutePrintPosition(100);
				// 	command.setText("颜色");
				// 	command.setAbsolutePrintPosition(180);
				// 	command.setText("尺码");
				// 	command.setAbsolutePrintPosition(270);
				// 	command.setText("单价");
				// 	command.setAbsolutePrintPosition(380);
				// 	command.setText("数量");
				// 	command.setAbsolutePrintPosition(480);
				// 	command.setText("金额");
				// 	command.setPrint()
				// 	command.bold(0);//加粗
				// 	// -------1
				// 	command.setText("86001W");
				// 	command.setAbsolutePrintPosition(100);
				// 	command.setText("黄色");
				// 	command.setAbsolutePrintPosition(180);
				// 	command.setText("均码");
				// 	command.setAbsolutePrintPosition(270);
				// 	command.setText("16947.92");
				// 	command.setAbsolutePrintPosition(390);
				// 	command.setText("1");
				// 	command.setAbsolutePrintPosition(480);
				// 	command.setText("19647.92");
				// 	command.setPrint()
				// 	// ------2
				// 	command.setText("86001W");
				// 	command.setAbsolutePrintPosition(100);
				// 	command.setText("黄色");
				// 	command.setAbsolutePrintPosition(180);
				// 	command.setText("均码");
				// 	command.setAbsolutePrintPosition(270);
				// 	command.setText("16947.92");
				// 	command.setAbsolutePrintPosition(390);
				// 	command.setText("1");
				// 	command.setAbsolutePrintPosition(480);
				// 	command.setText("19647.92");
				// 	command.setPrint()
				// 	// -------3
				// 	command.setText("86001W");
				// 	command.setAbsolutePrintPosition(100);
				// 	command.setText("黄色");
				// 	command.setAbsolutePrintPosition(180);
				// 	command.setText("均码");
				// 	command.setAbsolutePrintPosition(270);
				// 	command.setText("16947.92");
				// 	command.setAbsolutePrintPosition(390);
				// 	command.setText("1");
				// 	command.setAbsolutePrintPosition(480);
				// 	command.setText("19647.92");
				// 	command.setPrint();
				// 	//合计
				// 	command.bold(5);//加粗
				// 	command.setAbsolutePrintPosition(120);
				// 	command.setText("总数：10");
				// 	command.setAbsolutePrintPosition(320);
				// 	command.setText("合计：10000");
				// 	command.setPrint();
				// 	command.setAbsolutePrintPosition(120);
				// 	command.setText("实收：10000");
				// 	command.setAbsolutePrintPosition(320);
				// 	command.setText("找零：0");
				// 	command.setPrint();
				// 	// 收银员
				// 	command.rowSpace(120);//间距
				// 	command.setAbsolutePrintPosition(120);
				// 	command.setText("店员：何丹");
				// 	command.setAbsolutePrintPosition(320);
				// 	command.setText("会员：1000000000");
				// 	command.setPrint()
			
				// 	//提示
				// 	command.rowSpace(80);//间距
				// 	command.bold(2);//加粗
				// 	command.setSelectJustification(1);//居中
				// 	command.setText("售出商品购买后7天内,可凭小票退换");
				// 	command.setPrint();
				// 	command.setText("(注：吊牌未拆剪,商品未洗涤)");
				// 	command.setPrint();
			
				// 	//电话
				// 	command.setSelectJustification(0);//居左
				// 	command.setText("客服电话:(0571)86011123");
				// 	command.setPrint();
				// 	command.setText("联系地址:浙江省诸暨市暨阳街道健康路1-1号");
				// 	command.setPrint();
				command.setSelectJustification(1) //居中0左对齐1居中对齐2右对齐
				command.setText("询博技术支持");
				command.setPrintAndFeedRow(3);
				that.isReceiptSend = true;
				that.prepareSend(command.getData());
			
			
			},
			
			//准备发送，根据每次发送字节数来处理分包数量
			prepareSend(buff) {
				console.log(buff);
				let that = this
				let time = that.oneTimeData
				let looptime = parseInt(buff.length / time);
				let lastData = parseInt(buff.length % time);
				console.log(looptime + "---" + lastData)
				this.looptime = looptime + 1;
				this.lastData = lastData;
				this.currentTime = 1;
				that.Send(buff)
			},
			//分包发送
			Send(buff) {
				let that = this
				let {
					currentTime,
					looptime: loopTime,
					lastData,
					oneTimeData: onTimeData,
					printerNum: printNum,
					currentPrint
				} = that;
				let buf;
				let dataView;
				if (currentTime < loopTime) {
					buf = new ArrayBuffer(onTimeData)
					dataView = new DataView(buf)
				 for (var i = 0; i < onTimeData; ++i) {
						dataView.setUint8(i, buff[(currentTime - 1) * onTimeData + i])
					}
				} else {
					buf = new ArrayBuffer(lastData)
				 dataView = new DataView(buf)
					for (var i = 0; i < lastData; ++i) {
						dataView.setUint8(i, buff[(currentTime - 1) * onTimeData + i])
					}
				}
				console.log("第" + currentTime + "次发送数据大小为：" + buf.byteLength)
				let {
					BLEInformation
				} = that.Bluetooth;
			
				plus.bluetooth.writeBLECharacteristicValue({
					deviceId: BLEInformation.deviceId,
					serviceId: BLEInformation.writeServiceId,
					characteristicId: BLEInformation.writeCharaterId,
					value: buf,
					success: function(res) {
						console.log(res)
					},
					fail: function(e) {
						console.log(e)
					},
					complete: function() {
						currentTime++
						if (currentTime <= loopTime) {
							that.currentTime = currentTime;
							that.Send(buff)
						} else {
							//  uni.showToast({
							// title: '已打印第' + currentPrint + '张',
							//  })
							if (currentPrint == printNum) {
								that.looptime = 0;
								that.lastData = 0;
								that.currentTime = 1;
								that.isReceiptSend = false;
								that.isLabelSend = false;
								that.currentPrint = 1;
							} else {
								currentPrint++;
								that.currentPrint = currentPrint;
								that.currentTime = 1;
								that.Send(buff)
							}
						}
					}
				})
			},
			
			// 打印机结束
		}
	}
</script>

<style lang="scss" scoped>
	.flex2 {
		flex: 2;
	}

	.hongsetext {
		color: #FF0000;
	}

	.lvsetext {
		color: #00B855;
	}

	.youbianju {
		margin-right: 30rpx;
	}

	.huisetext {
		font-size: 24rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #999999;
	}

	.flex1 {
		flex: 1;
		text-align: right;
	}

	.flex1s {
		flex: 1;
		text-align: center;
	}

	.lansetext {
		font-size: 24rpx;
		font-family: PingFang SC-Bold, PingFang SC;
		font-weight: bold;
		color: #0BBDCB;
	}

	.lansetextline {
		text-decoration: underline #0BBDCB;
	}

	.lansebtn {
		color: #0BBDCB;
		background: rgba(11, 189, 203, .1);
	}

	.allbtn {
		width: 218rpx;
		height: 52rpx;
		border-radius: 50rpx;
		font-size: 24rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
	}

	.huisebtn {
		color: #999999;
		background: rgba(153, 153, 153, .1);
	}

	// /deep/.u-popup__content {
	// 	width: 80%;
	// }

	.zhengds {
		padding: 40rpx;
	}

	.shangpin {
		padding-bottom: 30rpx;
		border-bottom: 1px solid rgba(153, 153, 153, 0.05);
	}

	.btns {
		width: 198rpx;
		height: 62rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
	}

	.btn2 {
		color: #FFFFFF;
		background: #0BBDCB;
		border-radius: 74rpx;
		margin-left: 30rpx;
	}

	.btn1 {
		border: 1rpx solid #0BBDCB;
		color: #0BBDCB;
		background: #FFFFFF;
		border-radius: 74rpx;
	}

	.xiahuaxian {
		text-decoration: underline #333333;
	}

	.quedinng {
		margin-right: 30rpx;
	}

	.shurudh {
		border-radius: 24rpx;
		height: 60rpx;
		font-size: 30rpx;
		width: 460rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #999999;
		background: rgba(217, 217, 217, .2);
		text-align: center;
	}

	.topbox {
		border: 2rpx solid rgba(255, 255, 255, .1);
	}

	.dibu {
		width: 100%;
		padding: 30rpx 30rpx;
		position: fixed;
		z-index: 1000;
		bottom: 0;
		left: 0;
		box-sizing: border-box;
	}

	.tianjia {
		height: 62rpx;
		width: 136rpx;
		background: rgba(11, 189, 203, .1);
		font-size: 28rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #0BBDCB;
		border-radius: 98px 98px 98px 98px;
	}

	.inputs {
		height: 62rpx;
		width: 70%;
		font-size: 28rpx;
		padding-left: 44rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #999999;
	}

	.shuruk {
		width: 90%;
		background: rgba(217, 217, 217, .2);
		border-radius: 74rpx;
	}

	.shangtext {
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #000000;
	}

	.bigtext {
		font-size: 32rpx;
		font-family: PingFang SC-Bold, PingFang SC;
		font-weight: bold;
		color: #333333;
	}

	.leixingbtn1 {
		margin-right: 20rpx;
	}

	.leixingbtn {
		width: 218rpx;
		height: 52rpx;
		font-size: 20rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #999999;
		background: rgba(153, 153, 153, .1);
		border-radius: 50rpx;
	}

	// 定位点点点
	.diandiandian {
		position: relative;
	}

	.selectcontent {
		position: absolute;
		top: 50rpx;
		right: -6rpx;
		min-width: 250rpx;
		mix-width: 250rpx;
		text-align: center;
		background-color: rgba(11, 189, 203, 0.8);
		border-radius: 10rpx;
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #fff;
		word-wrap: break-word;
	}

	.sanjiao {
		position: absolute;
		top: -12rpx;
		right: 8rpx;
		background-image: url("@/static/image/system/sanjiao2.png");
		width: 40rpx;
		height: 12rpx;
		background-size: 100% 100%;
	}

	.leftimage {
		width: 34rpx;
		height: 34rpx;

		image {
			width: 100%;
			height: 100%;
		}
	}

	.itemselect {
		padding: 20rpx 30rpx;
	}
</style>
